
#ifndef __DSA_PUBLIC_KEY_H
#define __DSA_PUBLIC_KEY_H

#include <openssl/dsa.h>
#include "../iface/SSLInterface.h"
#include "PublicKey.h"
#include "CheckingKey.h"

/** An class encapsulating an DSA public key. */
class DSAPublicKey : public PublicKey, public CheckingKey
{
   public:
      DSAPublicKey();
      DSAPublicKey(const char *name);
      // Construct a duplicate of the public key
      DSAPublicKey(const DSAPublicKey &other);
      // Construct from PEM format
      DSAPublicKey(const char *pemtext, const char *name);
      // Construct from OpenSSL format
      DSAPublicKey(DSA *pubkey, const char *name);
      // Copy assignment operator
      DSAPublicKey &operator=(const DSAPublicKey &other);
      // Destroy public key
      ~DSAPublicKey();
      // Get context
      int getCryptlibContext(CRYPT_CONTEXT *keycontext);
      // Get Checking context
      int getCryptlibCheckingContext(CRYPT_CONTEXT *keycontext);
      // Get key components
      int getCryptlibKeyComponents(CRYPT_PKCINFO_DLP *dsakey);
      // Get new OpenSSL DSA object
      int getSSLKeyComponents(DSA **pubkey);
      // Get PEM data
      int getPEMKeyData(char **pemtext);
      // Get OpenSSH binary blob
      int getSSHKeyBlob(char **blob, int *reallength);
      // Get OpenSSH text with key label
      int getSSHKeyBlob(char **textblob, const char *keylabel);
      // Compare key to key
      int compareKeyEqual(PublicKey *pubkey);
      // Get key type name
      int getKeyType() { return KEY_TYPE_PUBLIC_DSA; }
      // To import from text - Base64 RAW or PEM
      int importKeyFromASCII(const char *text, const char *name);
      // To export to text - Base64 RAW or PEM
      int exportKeyToASCII(char **text);
      // Import from text with password
      int importKeyFromASCIIWithPassword(const char *text, const char *password, const char *name);
      // Export to text with password
      int exportKeyToASCIIWithPassword(char **text, const char *password);
   private:
      static int copyDSASSLPublicKey(DSA *dst, DSA *src);
      /** A pointer to the real DSA public key, held in SSL format. */
      DSA *key;
};

#endif
